#include <iostream>

// Subscripting下标运算符[]重载 -- 只能通过成员函数重载
using namespace std;
class vect{
public:
	vect(int size) {
		v=new int[size];
	}
	
	~vect() {
		delete[] v;
	}
	
	int& operator[](int i); //member function
	
private:
	int *v;
};

int& vect::operator[](int i) {
	cout << "Subscripting" << endl;
	return v[i]; 
}

int main()
{
	vect a(5);
	a[2]=12; // a.operator[](2)=12;
	cout<<a[2]<<endl; // a.operator[](2);
}